package org.ycy.data.generator.generator;

import org.ycy.data.generator.entity.NumberCheckInfo;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @ClassName AutoIncrement
 * @Description TODO
 * @Author 原长友
 * @Date 2023/3/5 22:34
 * @Version 1.0
 **/
public class AutoIncrementGenerator extends IGenerator<NumberCheckInfo> {

    private transient AtomicLong tmpValue;

    @Override
    public Object generator() {

        if (tmpValue == null || tmpValue.equals(checkInfo.getMaxValue())) {
            tmpValue = new AtomicLong(Long.parseLong(checkInfo.getMinValue().toString()));
        } else {
            tmpValue.incrementAndGet();
        }
        return tmpValue.get();
    }
}
